const commonConfig = require('./webpack.common');
const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const TerserPlugin = require('terser-webpack-plugin');

const productionConfig = Object.assign({}, commonConfig);

productionConfig.mode = 'production';

productionConfig.module.rules.unshift(
    {
        test: /index.tsx$/,
        use: [
            {
                loader: path.resolve(__dirname, 'src', 'loaders', 'api-loader.js'),
                options: {
                    url: ''
                }
            }
        ],
        include: path.resolve(__dirname, 'src', 'api'),
    }
);


productionConfig.plugins.unshift(new MiniCssExtractPlugin({
    filename: 'css/[name].css',
    chunkFilename: '[id].css',
}));

productionConfig.optimization = {
    minimizer: [new TerserPlugin()],
    splitChunks: {
        cacheGroups: {
            vendors: {
                priority: -10,
                test: /[\\/]node_modules[\\/]/
            }
        },
        chunks: 'async',
        minChunks: 1,
        minSize: 30000
    }
};

module.exports = productionConfig;